package com.pocketsweet.ui.fragments;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.lidroid.xutils.ViewUtils;
import com.pocketsweet.R;
import com.pocketsweet.model.MLUser;
import com.pocketsweet.service.UserService;
import com.pocketsweet.ui.uilib.FlowLayout;
import com.pocketsweet.ui.uilib.OnTabSelectedListener;
import com.pocketsweet.ui.uilib.RandomColorTagView;
import com.pocketsweet.utils.ToolKits;

public class WillingApperenceFragment extends Fragment {
	OnTabSelectedListener mListener;
	private FlowLayout HotTag = null;
	private MLUser mlUser = new MLUser();
	int flag = 0;
	private ArrayList<String> likeList = new ArrayList<String>();// 将值传给编辑页面，编辑页面不用再请求网络
	private String[] stringMood = { "身材高挑", "身材丰满", "身材娇小", "身材匀称", "小蛮腰",
			"长腿", "高瘦", "长发及腰", "肌肉发达" };

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View rootView = inflater.inflate(R.layout.fragment_like_hot, null);
		ViewUtils.inject(this, rootView);
		// initListview();
		return rootView;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		HotTag = (FlowLayout) getView().findViewById(R.id.HotTag);
		mlUser = UserService.getCurrentUser();
		if (mlUser.getSpecial() != null
				&& mlUser.getSpecial().size() > 0) {
			for (String like : mlUser.getSpecial()) {
				likeList.add(like);
			}
		}
		initTag(flag);
	}

	private void initTag(int flag) {
		String[] stringList = null;
		stringList = stringMood;
		for (int i = 0; i < stringList.length; i++) {
			final RandomColorTagView itemView = new RandomColorTagView(
					getActivity());
			itemView.setText(stringList[i]);
			final String tab = stringList[i];
			itemView.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
				}
			});
			itemView.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {
					String temp;
					for (int i = 0; i < likeList.size(); i++) {
						temp = likeList.get(i);
						if (temp.equals(tab)) {
							ToolKits.toast(getActivity(), "已添加过");
							return;
						}
					}
					mListener.onTabSelected(tab);
				}
			});
			HotTag.addView(itemView);
		}
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		try {
			mListener = (OnTabSelectedListener) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(activity.toString()
					+ " must implement OnTabSelectedListener");
		}
	}

}